const api = require('../../utils/api.js');
const config = require('../../config/config.js');
var app = new getApp()
Component({
  properties: {
    member_id: {
      type: Number,
      value: wx.getStorageSync('user').member_id
    },
    model_id: {
      type: Number,
      value: null
    },
    option_id: {
      type: Number,
      value: null
    },
    is_love: {
      type: Number,
      value: 0
    },

    is_fav: {
      type: Number,
      value: 0
    },
    love: {
      type: Number,
      value: 0
    },
    fav: {
      type: Number,
      value: 0
    },
    share: {
      type: Number,
      value: 0
    },
  },
  data: {
    // indicatorIndex: 0,
  },
  methods: {
    controlTap(event) {
      console.log(33333,event.currentTarget.dataset)
      if (!getApp().checkLogin()) return
      const {
        option_id,
        member_id,
        model_id,
        oper_type
      } = event.currentTarget.dataset
      let data = {
        id: option_id,
        member_id: member_id,
        model_id: model_id, //（1，产品；2，案例；3，视频；）
        oper_type: oper_type, //（1，点赞；2，收藏；3，分享；）
      }
      api.request('click_oper', 'POST',data).then(res => {
        let data = res.data.data
        switch(oper_type){
          case 1:
            this.setData({
              love:this.data.love + 1,
              is_love:1
            })
            break;
          case 2:
            this.setData({
              fav:this.data.fav + 1,
              is_fav:1
            })
          break;
        }
        
        
      })
      this.triggerEvent('updataEvent', option_id)
      // this.triggerEvent('change', current)
    },
    cancellTap(event) {
      console.log(33333,event.currentTarget.dataset)
      if (!getApp().checkLogin()) return
      const {
        option_id,
        member_id,
        model_id,
        oper_type
      } = event.currentTarget.dataset
      let data = {
        id: option_id,
        member_id: member_id,
        model_id: model_id, //（1，产品；2，案例；3，视频；）
        oper_type: oper_type, //（1，点赞；2，收藏；3，分享；）
      }
      api.request('cancel_oper', 'POST',data).then(res => {
        let data = res.data.data
        switch(oper_type){
          case 1:
            this.setData({
              love:this.data.love - 1,
              is_love:0
            })
            break;
          case 2:
            this.setData({
              fav:this.data.fav - 1,
              is_fav:0
            })
          break;
        }
        
      })

      this.triggerEvent('updataEvent', option_id)
    },
  }
})
